package com.xux.service.impl;

import org.bson.Document;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;

import java.util.List;

public class LookupLetPipelinesOperation implements AggregationOperation {

    private String from;
    private Document let;
    private Document pipeline;
    private String as;

    public LookupLetPipelinesOperation(String from, Document let, Document pipeline, String as) {
        this.from = from;
        this.let = let;
        this.pipeline = pipeline;
        this.as = as;
    }

    public static LookupLetPipelinesOperation lookup(String from, Document let, Document pipeline, String as) {
        return new LookupLetPipelinesOperation(from, let, pipeline, as);
    }

    @Override
    public Document toDocument(AggregationOperationContext context) {
        return new Document("$lookup",
                new Document("from", getFrom())
                        .append("let",
                                getLet())
                        .append("pipeline", List.of(getPipeline()))
                        .append("as", getAs()));
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public Document getLet() {
        return let;
    }

    public void setLet(Document let) {
        this.let = let;
    }

    public Document getPipeline() {
        return pipeline;
    }

    public void setPipeline(Document pipeline) {
        this.pipeline = pipeline;
    }

    public String getAs() {
        return as;
    }

    public void setAs(String as) {
        this.as = as;
    }
}